New Page
Moving Text
You've seen how to create Text Objects once when you created your score.
This slide will give you a little more practice!
Pay close attention to how the offset property works!
For example:
ball.center().offset(10, -50);
That code first centers the ball, then offsets it from that position 10 to the right (positive 'x' direction) and 50 up (negative 'y' direction).
Go ahead and do the activity below!
Buttons
Buttons are a lot of fun and very useful. Read the left column first then look at the example on the right!
When you click the button below it will center the planet and push it right!
Look at the code below the example on how it does that!
var planet = new sjs.Image("Images/planet.png");
var btn = new sjs.Button("I'M FLYING", function(){
planet.center();
planet.friction = 0;
planet.pushRight();
});
btn.centerH();
var startBtn = new sjs.Button("Play Pong!", function(){
window.location = "pong.html";
});
var startBtn - This creates a variable named startBtn, you can name the variable whatever you'd like.Activity
This Activity will walk you through the following:
You'll be opening a new text file to add your code for your menu.
MAC USERS: your File menu is at the very top left of your computer screen!
<!DOCTYPE html>
<html>
<head>
<title> Menu </title>
<script src="https://simplycodingcourses.com/files/simplyjs/simply.js"></script>
<script>
function start(){
sjs.open();
} //end start
</script>
</head>
<body onload="start()">
<h1> Menu </h1>
<div id="target" style="margin:auto;background:grey;"></div>
</body>
</html>
function start(){
sjs.open();
var menu_text = new sjs.Text("MENU",28,"blue");
} //end start
function start(){
sjs.open();
var menu_text = new sjs.Text("MENU",28,"blue");
menu_text.centerH();
} //end start
Only add the code in bold.
function start(){
sjs.open();
var menu_text = new sjs.Text("MENU",28,"blue");
menu_text.centerH();
var game_text = new sjs.Text("Use the Arrow Keys to Control the Paddles. Don't let the Ball get by you!",28,"#ff0");
} //end start
Only add the code in bold.
function start(){
sjs.open();
var menu_text = new sjs.Text("MENU",28,"blue");
menu_text.centerH();
var game_text = new sjs.Text("Use the Arrow Keys to Control the Paddles. Don't let the Ball get by you!",28,"#ff0");
game_text.centerH().offset(0, 30);
} //end start
Only add the code in bold.
function start(){
sjs.open();
var menu_text = new sjs.Text("MENU",28,"blue");
menu_text.centerH();
var game_text = new sjs.Text("Use the Arrow Keys to Control the Paddles. Don't let the Ball get by you!",28,"#ff0");
game_text.centerH().offset(0, 30);
var startBtn = new sjs.Button("Start", function(){
window.location = "pong.html";
});
} //end start
Only copy the code in bold above
function start(){
sjs.open();
var menu_text = new sjs.Text("MENU",28,"blue");
menu_text.centerH();
var game_text = new sjs.Text("Use the Arrow Keys to Control the Paddles. Don't let the Ball get by you!",28,"#ff0");
game_text.centerH().offset(0, 30);
var startBtn = new sjs.Button("Start", function(){
window.location = "pong.html";
});
startBtn.center();
} //end start
Only copy the code in bold above
/* startBtn code is here */
var info_text = new sjs.Text("Created By Jon Galt",20,"black");
info_text.bottom().centerH();
} //end start
If you menu page is functioning and looking how you'd like, go on to the Next Lesson!
If it's not working remember to check the console by Right Clicking in the browser and selecting Inspect Element.